package moe.hotk.common

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper

import scala.reflect.ClassTag
import scala.reflect.runtime.universe._

object Json {

  def stringify[A](input: A): String =
    mapper writeValueAsString input

  def parse[A: TypeTag : ClassTag](input: String): A =
    mapper readValue[A] input

  private lazy val mapper =
    new ObjectMapper with ScalaObjectMapper withSideEffect (_ registerModule DefaultScalaModule)

}
